//给定一个字符串，请你找出其中不含有重复字符的 最长子串 的长度。
// 输入: "abcabcbb"
// 输出: 3
// 解释: 因为无重复字符的最长子串是 "abc"，所以其长度为 3。
/**
 * @param {string} s
 * @return {number}
 */
let lengthOfLongestSubstring1 = function (s) {
    let max = 0
    let start = 0
    for (let i = 0; i < s.length; i++) {
        let curr = s.slice(start, i)
        let t = curr.indexOf(s[i])
        if (t === -1) {
            max = Math.max(max, i - start + 1)
        } else {
            start = start + t + 1
        }
        console.log(curr, start, i, max)
    }
    return max
}
let s1 = 'pwokew'
console.log(lengthOfLongestSubstring1(s1))
/**
 * @param {string} s
 * @return {number}
 */
let lengthOfLongestSubstring2 = function (s) {
    let max = 0
    let start = 0
    let map = new Map()
    for (let i = 0; i < s.length; i++) {
        if (map.has(s[i])) {
            start = Math.max(map.get(s[i]) + 1, start)
        }
        max = Math.max(max, i - start + 1)
        map.set(s[i], i)
        console.log(map, i, start, max)
    }
    return max
}
let s2 = 'pwokew'
console.log(lengthOfLongestSubstring2(s2))
